/*
 * export.c
 *
 *  Created on: Feb 21, 2014
 *      Author: kangstadt
 */


#include <stdio.h>
#include <unistd.h>
#include "virginian.h"

int main()
{
	// declare db state struct
	virginian *v;

	v = (virginian*)malloc(sizeof(virginian));

	// initialize state
	virg_init(v);

	//open database
	virg_db_open(v, "../db/comparedb2");

	// declare reader pointer
	virg_reader *r;

	// set optional query parameters
	v->use_multi = 0;	// not multithreaded
	v->use_gpu = 0;		// don't use GPU
	v->use_mmap = 0;		// don't use mapped memory

	// execute query
	virg_query(v, &r, "select test.id, test.uniformi, test.normali5 from test");

	// output result column names
	unsigned j;
	for(j = 0; j < r->res->fixed_columns; j++)
		printf("%s\t", r->res->fixed_name[j]);
	printf("\n");

	// output result data
	while(virg_reader_row(v, r) != VIRG_FAIL) {
		int *results = (int*)r->buffer;

		printf("%i\t%i\n", results[0], results[1]);
	}

	// clean up after query
	virg_reader_free(v, r);
	virg_vm_cleanup(v, r->vm);
	free(r);

	// close database
	virg_close(v);

}
